from abc import ABCMeta,abstractclassmethod
class Player:
    def __init__(self,face=None,body=None,arm=None,leg=None):
        self.face=face
        self.body=body
        self.arm=arm
        self.leg=leg

    def __str__(self):
        return "%s,%s.%s,%s"%(self.face,self.body,self.arm,self.leg)

#规定父类，要求子类必须重写以下四种方法
class PlayerBuilder(metaclass=ABCMeta):
    @abstractclassmethod
    #上述代码子类是约定俗称的实现这个方法，加上@abc.abstractmethod装饰器后严格控制子类必须实现这个方法
    def build_face(self):
        pass

    @abstractclassmethod
    def build_body(self):
        pass

    @abstractclassmethod
    def build_arm(self):
        pass

    @abstractclassmethod
    def build_leg(self):
        pass

class SexGirlBuilder(PlayerBuilder):
    def __init__(self):
        #这句有点懵
        self.player=Player()

    def build_face(self):
        self.player.face="漂亮脸蛋"

    def build_body(self):
        self.player.body="苗条"

    def build_arm(self):
        self.player.arm="漂亮胳膊"

    def build_leg(self):
        self.player.leg="大长腿"

class Monster(PlayerBuilder):
    def __init__(self):
        #这句有点懵
        self.player=Player()

    def build_face(self):
        self.player.face="怪兽脸"

    def build_body(self):
        self.player.body="怪兽身子"

    def build_arm(self):
        self.player.arm="长毛胳膊"

    def build_leg(self):
        self.player.leg="长毛腿"

#控制组装顺序
class PlayerDirector:
    def build_player(self,builder):
        builder.build_body()
        builder.build_face()
        builder.build_arm()
        builder.build_leg()
        return builder.player

#客户端调接口
builder=SexGirlBuilder()
#builder2=Monster()
director=PlayerDirector()
p=director.build_player(builder)
print(p)

